home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / cit.arc / NET.C < prev    next >
C/C++ Source or Header  |  1986-01-16  |  41KB  |  1,423 lines

  1. /************************************************************************/
  2. /*                net.c                    */
  3. /*                                    */
  4. /*    Networking functions.                        */
  5. /************************************************************************/
  6.  
  7. /************************************************************************/
  8. /*                history                 */
  9. /*                                    */
  10. /* 85Dec29 HAW    File created.  This will be .LIB rather than .OBJ.    */
  11. /* 85Oct28 HAW    Start adding file transfers.                */
  12. /* 85Oct27 JLS    New networking scheme -- transactional.         */
  13. /* 85Oct17 HAW    2400 baud support.                    */
  14. /* 85Sep18 HAW    Put 'system busy' message out (netstuff) to callers.    */
  15. /* 85Aug31 HAW    Add "outgoing" and "baud" feature to writeNet().    */
  16. /* 85Aug28 HAW    Fix minor bug in scheduler, allow for incoming.     */
  17. /* 85Aug24 HAW    Fix inMail() to allow for netMail to 'Sysop'.        */
  18. /* 85Jul22 JLS    Major changes to networker.                */
  19. /* 85Jun05 HAW    Add networking code to file MISC.C            */
  20. /************************************************************************/
  21.  
  22. #include "ctdl.h"
  23.  
  24. /************************************************************************/
  25. /*                contents                */
  26. /*                                    */
  27. /************************************************************************/
  28.  
  29. /************************************************************************/
  30. /*           External variable declarations in NET.C        */
  31. /************************************************************************/
  32. unsigned char     sectBuf[SECTSIZE + 5];
  33. int         counter;
  34. int         FinHour, FinMinute;
  35. label         normed, callerName, callerId;
  36.  
  37. char         searchNet(), normId(), getNetMessage();
  38. char         getLong(), callOut();
  39. unsigned char     inp();
  40.  
  41. #define needToCall(i) (netTab[i].ntflags.in_use == TRUE &&\
  42. (netTab[i].ntflags.normal_mail == TRUE || netTab[i].ntflags.room_files == TRUE))
  43.  
  44. #define HANGUP    0
  45. #define S_M_N    1
  46.  
  47. #define INTERVALS 8        /* Half second intervals        */
  48.  
  49. #define minimum(x,y)  ((x) < (y) ? (x) : (y))
  50.  
  51. /************************************************************************/
  52. /*           External variable definitions for NET.C        */
  53. /************************************************************************/
  54. extern struct config    cfg;        /* Lots an lots of variables    */
  55. extern struct logBuffer logBuf;     /* Person buffer        */
  56. extern struct aRoom    roomBuf;    /* Room buffer            */
  57. extern struct rTable    roomTab[];
  58. extern struct msgB    msgBuf,tempMess;
  59. extern struct netBuffer netBuf;
  60. extern struct netTable    *netTab;
  61. extern FILE        *upfd;
  62. extern int        thisNet;
  63. extern char        loggedIn;    /* Is we logged in?        */
  64. extern char        outFlag;    /* Output flag            */
  65. extern char        haveCarrier;    /* Do we still got carrier?    */
  66. extern unsigned char    modStat;    /* Needed so we don't die    */
  67. extern char        usingWCprotocol;/* WC flag            */
  68. extern char        WCError;
  69. extern int        thisRoom;
  70. extern int        thisLog;
  71.  
  72. /************************************************************************/
  73. /*           External function definitions for NET.C        */
  74. /************************************************************************/
  75. FILE *fopen();
  76. char *realloc();
  77.  
  78. /************************************************************************/
  79. /*    called() We've been called, so let's handle it            */
  80. /************************************************************************/
  81. called()
  82. {
  83.     char        processMail = FALSE;
  84.     label        tempNm;
  85.     int         count;
  86.     struct cmd_data cmds;
  87.  
  88.     for (count = 0; count < 4; count++)
  89.     cmds.fields[count][0] = 0;
  90.  
  91.     printf("Caller detected\n");
  92.  
  93.     if (!called_stabilize()) return ;
  94.  
  95.     printf("Caller stabilized\n");
  96.  
  97.     getId();
  98.     if (!haveCarrier) return;
  99.  
  100.     do {
  101.     getNextCommand(&cmds);
  102.     switch (cmds.command) {
  103.         case HANGUP:                    break;
  104.         case NORMAL_MAIL:    getMail(&cmds);
  105.                 processMail = TRUE;        break;
  106.         case R_FILE_REQ:    netFileReq(&cmds);        break;
  107.         default:        sPrintf(tempNm, "'%d' unknown.", cmds.command);
  108.                 reply(BAD, tempNm);        break;
  109.     }
  110.     } while (gotCarrier() && cmds.command != HANGUP);
  111.  
  112.     printf("Networking finished, terminating call from %s\n",callerName);
  113.     modStat = haveCarrier = FALSE;
  114.     interpret(cfg.pHangUp);
  115.     if (processMail) readMail();
  116. }
  117.  
  118. /************************************************************************/
  119. /*    getId() Gets nodeId and nodeName from caller.            */
  120. /************************************************************************/
  121. getId()
  122. {
  123.     int  increment();
  124.     int  i;
  125.     char *secRunner;
  126.  
  127.     if (!haveCarrier) return;
  128.     counter = 0;
  129.     readFile(increment);
  130.     if (!gotCarrier()) return modStat = haveCarrier = FALSE;
  131.     strCpy(callerId, sectBuf);
  132.     secRunner = sectBuf;
  133.     while (*secRunner != 0) secRunner++;
  134.     secRunner++;
  135.     strCpy(callerName, secRunner);
  136.     normId(callerId, normed);
  137.     if (!searchNet(normed)) {
  138.     sPrintf(msgBuf.mbtext, "New caller: %s (%s)", callerName, callerId);
  139.     aideMessage(FALSE);
  140.     }
  141.     printf("Call from %s (%s)\n", callerName, callerId);
  142. }
  143.  
  144. /************************************************************************/
  145. /*    getNextCommand() Gets next command from caller            */
  146. /************************************************************************/
  147. getNextCommand(cmds)
  148. struct cmd_data *cmds;
  149. {
  150.     int increment();
  151.  
  152.     counter = 0;
  153.     readFile(increment);
  154.     if (!gotCarrier()) return modStat = haveCarrier = FALSE;
  155.     grabCommand(cmds, sectBuf);
  156. }
  157.  
  158. /************************************************************************/
  159. /*    grabCommand() Pulls network cmds out of specified buffer    */
  160. /************************************************************************/
  161. grabCommand(cmds, sect)
  162. char *sect;
  163. struct cmd_data *cmds;
  164. {
  165.     int fcount = 0;
  166.  
  167.     cmds->command = sect[0];
  168.     sect++;
  169.     while (sect[0] > 0 && fcount < 4) {
  170.     strCpy(cmds->fields[fcount++], sect);
  171.     while (*sect != 0) sect++;
  172.     sect++;
  173.     }
  174. }
  175.  
  176. /************************************************************************/
  177. /*    reply() Replies to caller                    */
  178. /************************************************************************/
  179. reply(state, reason)
  180. char state;
  181. char *reason;
  182. {
  183.     if (!doWC(STARTUP)) {
  184.     no_good("Couldn't send reply to %s!", TRUE);
  185.     modStat = haveCarrier = FALSE;
  186.     interpret(cfg.pHangUp);
  187.     return;
  188.     }
  189. if (cfg.debug) printf("Replying %s\n", (state == BAD) ? "BAD:" : "GOOD");
  190.     sendWCChar(state);
  191.     if (state == BAD) {
  192.     mWCprintf("%s", reason);
  193. if (cfg.debug) printf("%s", reason);
  194.     }
  195.     sendWCChar(0);
  196.     doWC(FINISH);
  197. }
  198.  
  199. /************************************************************************/
  200. /*    getMail() Grabs mail from caller                */
  201. /************************************************************************/
  202. getMail(cmds)
  203. struct cmd_data *cmds;
  204. {
  205.     label tempNm;
  206.     int   putFLChar();
  207.  
  208.     printf("Receiving mail from %s\n", callerName);
  209.     reply(GOOD, "");
  210.     strCpy(tempNm, "a:tempmail.$$$");
  211.     tempNm[0]  = cfg.netDisk + 'a';
  212.     if ((upfd = fopen(tempNm, "wrb")) == NULL) {
  213.     crashout("Couldn't create networker temporary file!");
  214.     }
  215.     readFile(putFLChar);
  216.     fclose(upfd);
  217. }
  218.  
  219. /************************************************************************/
  220. /*    netFileReq() Handles request for file transfer            */
  221. /************************************************************************/
  222. netFileReq(cmds)
  223. struct cmd_data *cmds;
  224. {
  225.     int  roomSlot;
  226.     int  data;
  227.     char reason[50];
  228.     FILE *fd;
  229.  
  230. if (cfg.debug) printf("\nRequest for %s from %s\n", cmds->fields[0],
  231. cmds->fields[1]);
  232.     if ((roomSlot = roomExists(cmds->fields[0])) == ERROR ||
  233.             roomTab[roomSlot].rtflags.MSDOSDIR != 1) {
  234.     sPrintf(reason, "Room %s does not exist.", cmds->fields[0]);
  235.     reply(BAD, reason);
  236.     return;
  237.     }
  238.  
  239.     getRoom(roomSlot);
  240.  
  241.     if (!setSpace(roomBuf.rbdisk, roomBuf.rbdirname)) {
  242.     sPrintf(reason, "Couldn't open directory for %s.", cmds->fields[0]);
  243.     reply(BAD, reason);
  244.     return;
  245.     }
  246.  
  247.     if ((fd = fopen(cmds->fields[1], "rb")) == NULL) {
  248.     sPrintf(reason, "There is no '%s' in %s.", cmds->fields[1],
  249.                            cmds->fields[0]);
  250.     reply(BAD, reason);
  251.     if (strLen(roomBuf.rbdirname) != 0) setSpace(roomBuf.rbdisk, "..");
  252.     setSpace(cfg.homeDisk, "");
  253.     return;
  254.     }
  255.  
  256.     reply(GOOD, "");
  257.     if (doWC(STARTUP)) {
  258.     while ((data = fgetc(fd)) != EOF && data != -1)
  259.         if (!sendWCChar(data)) break;
  260.     doWC(FINISH);
  261.     }
  262.     fclose(fd);
  263.     if (strLen(roomBuf.rbdirname) != 0) setSpace(roomBuf.rbdisk, "..");
  264.     setSpace(cfg.homeDisk, "");
  265.     sPrintf(msgBuf.mbtext,
  266.         "File \"%s\" downloaded from %s during networking by %s.",
  267.         cmds->fields[1], roomBuf.rbname, callerName);
  268.     aideMessage(FALSE);
  269. }
  270.  
  271. /************************************************************************/
  272. /*    increment()                            */
  273. /************************************************************************/
  274. increment(c)
  275. unsigned char c;
  276. {
  277.     sectBuf[counter++] = c;
  278.     if (counter > SECTSIZE+2) {
  279.     interpret(cfg.pHangUp);
  280.     modStat = haveCarrier = FALSE;
  281.     }
  282.     return TRUE;
  283. }
  284.  
  285. /************************************************************************/
  286. /*    normId() Normalizes a node id.                    */
  287. /************************************************************************/
  288. char normId(source, dest)
  289. label source, dest;
  290. {
  291.     while (!isalpha(*source) && *source)
  292.     source++;
  293.     if (!*source) return FALSE;
  294.     *dest++ = toUpper(*source++);
  295.     while (!isalpha(*source) && *source)
  296.     source++;
  297.     if (!*source) return FALSE;
  298.     *dest++ = toUpper(*source++);
  299.     while (*source) {
  300.     if (isdigit(*source))
  301.         *dest++ = *source;
  302.     source++;
  303.     }
  304.     *dest = '\0';
  305.     return TRUE;
  306. }
  307.  
  308. /************************************************************************/
  309. /*    called_stabilize() Attempts to stabilize communication on    */
  310. /*               receiver end.                */
  311. /************************************************************************/
  312. called_stabilize()
  313. {
  314.     int  Time = 0, f, baudRunner = 0;
  315.     char noGood, notFinished, notDone = TRUE;
  316.     char laterMessage[100];
  317.  
  318.     pause(100);     /* Pause a full second */
  319.     while (notDone) {
  320.     noGood = TRUE;
  321.  
  322.     if (cfg.search_baud) {
  323.         while (MIReady())    inp();        /* Clear garbage    */
  324.         while (gotCarrier() && noGood && Time < 20) {
  325.         Time++;
  326.            for (notFinished = TRUE; noGood && gotCarrier() && notFinished;){
  327.             interpret(cfg.pBauds[baudRunner]);
  328.             noGood = check_for_init();
  329.             if (cfg.debug) printf(".\n");
  330.             notFinished = !(baudRunner == cfg.sysBaud);
  331.             baudRunner = (baudRunner + 1) % (cfg.sysBaud + 1);
  332.         }
  333.         }
  334.     }
  335.  
  336.     else {
  337.         interpret(cfg.pBauds[interpret(cfg.pCheckBaud)]);
  338.  
  339.         for (; gotCarrier() && Time < 20 && noGood; Time++) {
  340.         noGood = check_for_init();
  341.         if (cfg.debug) printf(".\n");
  342.         }
  343.         if (cfg.debug) printf("\n");
  344.     }
  345.  
  346.     if (!gotCarrier()) {
  347.         modStat = haveCarrier = FALSE;
  348.         printf("Lost carrier\n");
  349.         return FALSE;
  350.     }
  351.  
  352.     if (noGood && Time == 20) {
  353.         outFlag = IMPERVIOUS;
  354.         sPrintf(laterMessage,
  355.  "System will be in network mode for another %d minutes; please call back.\n",
  356.                         timeLeft());
  357.         if (cfg.search_baud) {
  358.         for (baudRunner = cfg.sysBaud; baudRunner > -1; baudRunner--) {
  359.             interpret(cfg.pBauds[baudRunner]);
  360.             mPrintf(laterMessage);
  361.         }
  362.         }
  363.         else
  364.         mPrintf(laterMessage);
  365.         interpret(cfg.pHangUp);
  366.         notDone = modStat = haveCarrier = FALSE;
  367.         outFlag = OUTOK;
  368.     }
  369.     else {
  370. if (cfg.debug) printf("&");
  371.         outMod(~7 );
  372.         outMod(~13);
  373.         outMod(~69);
  374.         f = receive(2);
  375.         if (f == ACK)
  376.         return TRUE ;
  377.         else if (cfg.debug) printf("%d ", f);
  378.  
  379.         if (!gotCarrier())
  380.         modStat = haveCarrier = notDone = FALSE;
  381.     }
  382.     }
  383.     if (!gotCarrier())
  384.     modStat = haveCarrier = FALSE;
  385.     return FALSE;
  386. }
  387.  
  388. /************************************************************************/
  389. /*    check_for_init() Looks for networking initialization sequence    */
  390. /************************************************************************/
  391. check_for_init()
  392. {
  393. #ifdef OLD_STYLE
  394.     int i, j, x;
  395.  
  396.     for (i = 0; i < INTERVALS && !MIReady(); i++)
  397.     for (j = 0; j < 250 && !MIReady(); j++)
  398.         shortPause();
  399.  
  400.     if (MIReady()) {
  401.     if ((x = inp()) != 7) {
  402.         if (cfg.debug) printf("1 was %d\n", x);
  403.         return TRUE;
  404.     }
  405.     x = receive(2);
  406.     if (x != 13) {
  407.         if (cfg.debug) printf("1 was 7, 2 was %d\n", x);
  408.         return TRUE;
  409.     }
  410.     x = receive(2);
  411.     if (x != 69) {
  412.         if (cfg.debug) printf("1 was 7, 2 was 13, 3 was %d\n", x);
  413.         return TRUE;
  414.     }
  415.     if (cfg.debug) printf("SUCCESS\n");
  416.     return FALSE;
  417.     }
  418.     return TRUE;
  419. #else
  420.     int       count, timeOut;
  421.     unsigned char thisVal, lastVal;
  422.  
  423.     lastVal = 0;
  424.     timeOut = (INTERVALS / 2) * (500);
  425.     for (count = 0; count < timeOut; count++) {
  426.     if (MIReady()) {
  427.         thisVal = inp();
  428. if (cfg.debug) printf("%d ", thisVal);
  429.         switch (thisVal) {
  430.         case 7:  lastVal = 7; break;
  431.         case 13:
  432.              if (lastVal == 7) lastVal = 13;
  433.              else           lastVal = 0;
  434.              break;
  435.         case 69:
  436.              if (lastVal == 13) return FALSE;
  437.              else           lastVal = 0;
  438.              break;
  439.         default:
  440.              lastVal = 0;
  441.         }
  442.     }
  443.     else shortPause();
  444.     }
  445.     return TRUE;
  446. }
  447.  
  448. /************************************************************************/
  449. /*    searchNet() Searches net for the given Id.            */
  450. /************************************************************************/
  451. char searchNet(forId)
  452. char *forId;
  453. {
  454.     int rover;
  455.     label temp;
  456.  
  457.     for (rover = 0; rover < cfg.netSize; rover++) {
  458.     if (netTab[rover].ntflags.in_use &&
  459.         hash(forId) == netTab[rover].ntidhash) {
  460.         getNet(rover);
  461.         normId(netBuf.netId, temp);
  462.         if (strCmpU(temp, forId) == SAMESTRING)
  463.         return TRUE;
  464.     }
  465.     }
  466.     return FALSE;
  467. }
  468.  
  469. /************************************************************************/
  470. /*    readMail() Integrates mail into the data base            */
  471. /************************************************************************/
  472. readMail()
  473. {
  474.     label tempNm;
  475.  
  476.     strCpy(tempNm, "a:tempmail.$$$");
  477.     tempNm[0] = cfg.netDisk + 'a';
  478.     if ((upfd = fopen(tempNm, "rb")) == NULL) {
  479.     no_good("Couldn't open tempmail file from %s.", TRUE);
  480.     return;
  481.     }
  482.     getRoom(MAILROOM);
  483.     while (getNetMessage()) {
  484.     if (strCmpU(cfg.nodeId + cfg.codeBuf, tempMess.mborig) != SAMESTRING)
  485.         inMail();
  486.     }
  487.     fclose(upfd);
  488.     unlink(tempNm);
  489. }
  490.  
  491. /************************************************************************/
  492. /*    getNetMessage() gets a message from a global file        */
  493. /************************************************************************/
  494. char getNetMessage()
  495. {
  496.     int marker, c;
  497.  
  498.     marker = 0;
  499.     while (marker != 'M') {
  500.     while ((marker = getc(upfd)) != -1 && marker == ' ')
  501.         ;
  502.     if (marker == -1) {
  503.         return FALSE;
  504.     }
  505.     switch (marker) {
  506.         case 'A':
  507.         getNetStr(tempMess.mbauth);
  508.         break;
  509.         case 'D':
  510.         getNetStr(tempMess.mbdate);
  511.         break;
  512.         case 'N':
  513.         getNetStr(tempMess.mboname);
  514.         break;
  515.         case 'O':
  516.         getNetStr(tempMess.mborig);
  517.         break;
  518.         case 'R':
  519.         getNetStr(tempMess.mbroom);
  520.         break;
  521.         case 'S':
  522.         getNetStr(tempMess.mbsrcId);
  523.         break;
  524.         case 'T':
  525.         getNetStr(tempMess.mbto);
  526.         break;
  527.         case 'C':
  528.         getNetStr(tempMess.mbtime);
  529.         break;
  530.         default:
  531.         if (marker != 'M')
  532.             while ((c = getc(upfd)) != -1 && c != '\0')
  533.             ;
  534.             break;
  535.     }
  536.     }
  537.     getNetStr(tempMess.mbtext);
  538.     return TRUE;
  539. }
  540.  
  541. /************************************************************************/
  542. /*    getNetStr() gets a string from networked message        */
  543. /************************************************************************/
  544. getNetStr(place)
  545. char *place;
  546. {
  547.     int i, c;
  548.  
  549.     i = 0;
  550.     do    {
  551.     c = getc(upfd);
  552.     if (c == '\r') c = '\n';
  553.     place[i++] = c;
  554.     } while (c != -1 && c != '\0');
  555. }
  556.  
  557. /************************************************************************/
  558. /*    inMail() integrates mail into database                */
  559. /************************************************************************/
  560. inMail()
  561. {
  562.     int          logNo;
  563.     struct logBuffer lBuf;
  564.  
  565.     if (!tempMess.mbto[0]) return ;
  566.     logNo = findPerson(tempMess.mbto, &lBuf);
  567.     strCpy(msgBuf.mbto, tempMess.mbto);
  568.     if (logNo == ERROR && hash(tempMess.mbto) != hash("Sysop")) {
  569.     printf("Mail to '%s' cannot be delivered.\n", tempMess.mbto);
  570.     return;
  571.     }
  572.     else printf("Delivering mail to '%s'\n", tempMess.mbto);
  573.     strCpy(msgBuf.mbto,   lBuf.lbname);
  574.     strCpy(tempMess.mbto, lBuf.lbname);
  575.     putNetMessage();
  576.     noteMessage(&lBuf, logNo);
  577. }
  578.  
  579. /************************************************************************/
  580. /*    caller() we've called and got carrier, so let's goferit     */
  581. /************************************************************************/
  582. caller()
  583. {
  584.  
  585.     printf("Carrier detected\n");
  586.     caller_stabilize();
  587.  
  588.     if (!haveCarrier) return ;    /* Abort */
  589.  
  590.     printf("Have stabilized call with receiver\n");
  591.     sendId();
  592.  
  593.     if (netBuf.nbflags.normal_mail)
  594.     sendMail();
  595.  
  596.     if (netBuf.nbflags.room_files)
  597.     askFiles();
  598.  
  599.     sendHangUp();
  600.     while (gotCarrier()) ;
  601.  
  602.     printf("\nCall to %s finished successfully\n", netBuf.netName);
  603.  
  604.     modStat = haveCarrier = FALSE;
  605.     putNet(thisNet);
  606. }
  607.  
  608. /************************************************************************/
  609. /*    caller_stabilize() Tries to stabilize the call --        */
  610. /*               baud is already set                */
  611. /************************************************************************/
  612. caller_stabilize()
  613. {
  614.     int Time, i, j;
  615.     int x1, x2, x3;
  616.  
  617.     pause(200);     /* Pause a full 2 seconds            */
  618.     while (MIReady())    inp();            /* Clear garbage    */
  619.     for (Time = 0; Time < 20 && gotCarrier(); Time++) {
  620.     if (cfg.debug) printf(".");
  621.     outMod(7);
  622.     pause(10);
  623.     outMod(13);
  624.     pause(10);
  625.     outMod(69);
  626.     for (j = 0; j < INTERVALS && !MIReady(); j++)
  627.         for (i = 0; i < 250 && !MIReady(); i++)
  628.         shortPause();
  629.     if (MIReady()) {
  630.         x1 = receive(2);
  631.         x2 = receive(2);
  632.         if (x2 != ERROR) x3 = receive(2);
  633.         if (x1 == 248 &&
  634.         x2 == 242 &&
  635.         x3 == 186) {
  636.         outMod(ACK);
  637.         if (cfg.debug) printf("ACKing, Call stabilized\n");
  638.         return;
  639.         }
  640.         else if (cfg.debug) printf("%d %d %d\n", x1, x2, x3);
  641.     }
  642.     }
  643.     printf("Call not stabilized\n");
  644.     modStat = haveCarrier = FALSE;
  645.     interpret(cfg.pHangUp);
  646. }
  647.  
  648. /************************************************************************/
  649. /*    sendId() Sends ID to the receiver                */
  650. /************************************************************************/
  651. sendId()
  652. {
  653.     char *reason;
  654.     char message[40];
  655.  
  656.     if (!haveCarrier) return;
  657.     if (!doWC(STARTUP)) {
  658.     no_good("Couldn't transfer ID to %s!", TRUE);
  659.     modStat = haveCarrier = FALSE;
  660.     interpret(cfg.pHangUp);
  661.     return;
  662.     }
  663.  
  664.     mWCprintf("%s", cfg.codeBuf + cfg.nodeId  );
  665.     mWCprintf("%s", cfg.codeBuf + cfg.nodeName);
  666.  
  667.     if (WCError) {
  668.     if (!gotCarrier()) {
  669.         modStat = haveCarrier = FALSE;
  670.         reason = "carrier loss";
  671.     }
  672.     else reason = "WC abort: 10 errors or CANCEL";
  673.     doWC(FINISH);
  674.     strCpy(message, "Couldn't transfer ID to %s! ");
  675.     strCat(message, reason);
  676.     no_good(message, TRUE);
  677.     return;
  678.     }
  679.     doWC(FINISH);
  680. }
  681.  
  682. /************************************************************************/
  683. /*    sendMail()  send normal mail to receiver            */
  684. /************************************************************************/
  685. sendMail()
  686. {
  687.     struct cmd_data cmds;
  688.     int i, nor_mail;
  689.     char *reason, message[50];
  690.  
  691.     if (!haveCarrier) return;
  692.     printf("Sending normal mail\n");
  693.  
  694.     cmds.command = NORMAL_MAIL;
  695.     for (i = 0; i < 4; i++)
  696.     cmds.fields[i][0] = 0;
  697.     if (!sendNetCommand(&cmds, "Couldn't send Normal Mail command to %s!"))
  698.     return;
  699.  
  700.     if (!doWC(STARTUP)) {
  701.     no_good("Couldn't transfer ID to %s!", TRUE);
  702.     modStat = haveCarrier = FALSE;
  703.     interpret(cfg.pHangUp);
  704.     return;
  705.     }
  706.     nor_mail = s_m_n();        /* Send normal mail       */
  707.  
  708.     if (WCError) {
  709.     if (!gotCarrier()) {
  710.         modStat = haveCarrier = FALSE;
  711.         reason = "carrier loss";
  712.     }
  713.     else reason = "WC abort: 10 errors or CANCEL";
  714.     doWC(FINISH);
  715.     strCpy(message, "Couldn't transfer ID to %s! ");
  716.     strCat(message, reason);
  717.     no_good(message, TRUE);
  718.     return;
  719.     }
  720.     else {
  721.     printf("\nSuccessful transfer of %d messages\n", nor_mail);
  722.     netBuf.nbflags.normal_mail = FALSE;
  723.     }
  724.     doWC(FINISH);
  725. }
  726.  
  727. /************************************************************************/
  728. /*    askFiles() ask for file(s) from caller                */
  729. /************************************************************************/
  730. askFiles()
  731. {
  732.     label  data;
  733.     int    putFLChar(), i;
  734.     char   mess[130], *cd, *gcdir();
  735.     FILE   *temp;
  736.     struct cmd_data cmds;
  737.     struct fl_req file_data;
  738.  
  739.     sPrintf(data, "a:%d.rfl", thisNet);
  740.     data[0] = cfg.netDisk + 'a';
  741.     temp = fopen(data, "rb");
  742.     if (temp == NULL) {
  743.     no_good("Couldn't open room request file for %s", FALSE);
  744.     netBuf.nbflags.room_files = FALSE;
  745.     }
  746.     else {
  747.     while (fread(&file_data, sizeof (file_data), 1, temp) == 1 &&
  748.                  gotCarrier()){
  749.         setSpace(toUpper(file_data.drive) - 'A', "");
  750.         cd = gcdir("");
  751.         if (chdir(file_data.path) != EOF) {
  752.         cmds.command = R_FILE_REQ;
  753.         for (i = 2; i < 4; i++)
  754.             cmds.fields[i][0] = 0;
  755.         strCpy(cmds.fields[0], file_data.room);
  756.         strCpy(cmds.fields[1], file_data.roomfile);
  757.     if (cfg.debug) printf("Asking for file %s in %s\n", file_data.roomfile,
  758.     file_data.room);
  759.         if (!sendNetCommand(&cmds, "Couldn't ask for files from %s!")) {
  760.             if (cfg.debug) printf("No file reported.\n");
  761.             strCpy(mess, "%s reports: ");
  762.             strCat(mess, sectBuf + 1);
  763.             no_good(mess, FALSE);
  764.         }
  765.         else {
  766.             upfd = fopen(file_data.filename, "wb");
  767.             readFile(putFLChar);
  768.             fclose(upfd);
  769.         }
  770.         chdir(cd);
  771.         if (cfg.debug) printf("About to call free(cd);\n");
  772.         free(cd);
  773.         if (cfg.debug) printf("Out of call free(cd);\n");
  774.         }
  775.         setSpace(cfg.homeDisk, "");
  776.     }
  777.     fclose(temp);
  778.     if (gotCarrier()) {
  779.         unlink(data);
  780.         netBuf.nbflags.room_files = FALSE;
  781.     }
  782.     else haveCarrier = modStat = FALSE;
  783.     }
  784. }
  785.  
  786. /************************************************************************/
  787. /*    sendNetCommand() Sends a command to the receiver        */
  788. /************************************************************************/
  789. sendNetCommand(cmds, error)
  790. struct cmd_data *cmds;
  791. char        *error;
  792. {
  793.     int count, increment();
  794.  
  795.     if (!doWC(STARTUP)) {
  796.     no_good(error, TRUE);
  797.     modStat = haveCarrier = FALSE;
  798.     interpret(cfg.pHangUp);
  799.     return;
  800.     }
  801.     sendWCChar(cmds->command);
  802.     for (count = 0; count < 4; count++)
  803.     if (cmds->fields[count][0])
  804.         mWCPrintf("%s", cmds->fields[count]);
  805.     sendWCChar(0);
  806.     doWC(FINISH);
  807.     counter = 0;
  808.     if (cmds->command == HANGUP) return TRUE;
  809. if (cfg.debug) printf("part 1 finished\n");
  810.     readFile(increment);
  811. if (cfg.debug) printf("part 2 finished\n");
  812.     if (sectBuf[0] == BAD) return FALSE;
  813.     return TRUE;
  814. }
  815.  
  816. /************************************************************************/
  817. /*    sendHangUp() Send hangup command to receiver            */
  818. /************************************************************************/
  819. sendHangUp()
  820. {
  821.     struct cmd_data cmds;
  822.     int         i;
  823.  
  824.     cmds.command = HANGUP;
  825.     for (i = 0; i < 4; i++)
  826.     cmds.fields[i][0] = 0;
  827.     sendNetCommand(&cmds, "Couldn't send HANGUP command to %s");
  828. }
  829.  
  830. /************************************************************************/
  831. /*    no_good() does error messages                    */
  832. /************************************************************************/
  833. no_good(str, hup)
  834. char *str;
  835. char hup;
  836. {
  837.     sPrintf(msgBuf.mbtext, str, netBuf.netName);
  838.     if (hup) {
  839.     interpret(cfg.pHangUp);
  840.     modStat = haveCarrier = FALSE;
  841.     }
  842.     aideMessage(FALSE);
  843. }
  844.  
  845. /************************************************************************/
  846. /*    s_m_n() Send mail normal (non-route mail)            */
  847. /************************************************************************/
  848. s_m_n()
  849. {
  850.     FILE  *ptrs;
  851.     char  c;
  852.     label blah, fn;
  853.     ulong id;
  854.     int   val, messCount = 0;
  855.     unsigned location;
  856.  
  857.     sPrintf(fn, "a:%d.ml", thisNet);
  858.     fn[0] = cfg.netDisk + 'a';
  859.     if ((ptrs = fopen(fn, "rb")) == NULL) {
  860.     sPrintf(msgBuf.mbtext, "No mail file to send to %s?", netBuf.netName);
  861.     aideMessage(FALSE);
  862.     return 0;
  863.     }
  864.  
  865.     usingWCprotocol = TRUE;
  866.     while (1) {
  867.     id = 0l;
  868.     if (!getLong(ptrs, &id)) break;
  869.     location = fgetc(ptrs) << 8;
  870.     location += fgetc(ptrs);
  871.     printMessage(location, id, blah);
  872.     messCount++;
  873.     }
  874.     usingWCprotocol = FALSE;
  875.     fclose(ptrs);
  876.     if (!WCError) {
  877.     unlink(fn);
  878.     return messCount;
  879.     }
  880.     printf("\nUnsuccessful transfer of normal mail\n");
  881.     return 0;
  882. }
  883.  
  884. /************************************************************************/
  885. /*    getLong() Gets a long from the specified file            */
  886. /************************************************************************/
  887. char getLong(fd, l)
  888. FILE *fd;
  889. ulong *l;
  890. {
  891.     int  val;
  892.     char c;
  893.  
  894.     val = fgetc(fd);
  895.     if (val == -1) return FALSE;
  896.     c = val;
  897.     *l += (val << 24);
  898.     val = fgetc(fd);
  899.     c = val;
  900.     *l += (val << 16);
  901.     val = fgetc(fd);
  902.     c = val;
  903.     *l += (val << 8);
  904.     val = fgetc(fd);
  905.     c = val;
  906.     *l += (val);
  907.     return TRUE;
  908. }
  909.  
  910. /************************************************************************/
  911. /*    netController() Handles the net stuff                */
  912. /************************************************************************/
  913. netController()
  914. {
  915.     int x;
  916.     int searcher = 0, start, first;
  917.     ulong waitTime, count;
  918.  
  919.     loggedIn = FALSE;            /* Let's be VERY sure.        */
  920.     thisLog = -1;
  921.     printf("\n---------------In Networking Mode--------------\n");
  922.     modStat = haveCarrier = FALSE;
  923.     srand(cfg.catChar);     /* This should be nicely random     */
  924.     setTime();
  925.  
  926.     while ((x = timeLeft()) > 0) {    /* "Can we say inefficient?"    */
  927.     waitTime = rand();
  928.     while (waitTime > minimum(5, ((x/2)))) waitTime /= 2;
  929.     /*    for (count = 0; count < waitTime * 6000; count++) {    */
  930.     for (count = 0; count < waitTime * 6000 && !KBReady(); count++) {
  931.         pause(1);
  932.         if (gotCarrier()) break;
  933.     }
  934. if(KBReady()) getCh();
  935.     if (gotCarrier()) {
  936.         modStat = haveCarrier = TRUE;
  937.         called();
  938.     }
  939.     if (cfg.netSize != 0) {
  940.         start = searcher;
  941.         do {
  942.         if (needToCall(searcher)) {
  943.             if (callOut(searcher))
  944.             caller();
  945.             for (count = 0; count < 20 && !gotCarrier(); count++)
  946.                /* Give the modem a chance to recover   */
  947.             pause(50);
  948.             if (gotCarrier()) {
  949.             modStat = haveCarrier = TRUE;
  950.             called();
  951.             }
  952.         }
  953.         searcher = (searcher + 1) % cfg.netSize;
  954.         } while ((searcher+1) % cfg.netSize != start);
  955.     }
  956.     }
  957.     printf("\n---------------Out of Networking Mode--------------\n");
  958.     for (searcher = 0; searcher < cfg.netSize; searcher++)
  959.     if (needToCall(searcher)) break;
  960.     if (searcher < cfg.netSize) {
  961.     sPrintf(msgBuf.mbtext, "The following systems could not be reached: ");
  962.     for (searcher = 0, first = 1; searcher < cfg.netSize; searcher++)
  963.         if (needToCall(searcher)) {
  964.         if (!first) strCat(msgBuf.mbtext,", ");
  965.         first = FALSE;
  966.         getNet(searcher);
  967.         strCat(msgBuf.mbtext, netBuf.netName);
  968.         }
  969.     strCat(msgBuf.mbtext, ".");
  970.     aideMessage(FALSE);
  971.     }
  972.     interpret(cfg.pInitPort);
  973.     modStat = haveCarrier = FALSE;
  974. }
  975.  
  976. /************************************************************************/
  977. /*    setTime() Sets up some global variables for the networker    */
  978. /************************************************************************/
  979. setTime()
  980. {
  981.     int yr, hr, min, dy;
  982.     char *mn;
  983.  
  984.     getdate(&yr, &mn, &dy, &hr, &min);
  985.     FinHour   = hr + cfg.netLength / 60;
  986.     FinMinute = cfg.netLength % 60;
  987. }
  988.  
  989. /************************************************************************/
  990. /*    timeLeft() Does a rough estimate of how much time left        */
  991. /************************************************************************/
  992. int timeLeft()
  993. {
  994.     int yr, hr, min, dy;
  995.     char *mn;
  996.  
  997.     getdate(&yr, &mn, &dy, &hr, &min);
  998.     if (hr == FinHour && min > FinMinute) return -1;
  999.     if (hr > FinHour) return -1;
  1000.     return ((FinHour - hr) * 60 + abs(min - FinMinute));
  1001. }
  1002.  
  1003. /************************************************************************/
  1004. /*    callOut() Attempts to call some other system.            */
  1005. /************************************************************************/
  1006. char callOut(i)
  1007. int i;
  1008. {
  1009.     char  call[80], ours[10], theirs[10];
  1010.     label blip1, blip2;
  1011.  
  1012.     getNet(i);
  1013.     printf("Calling %s @ %s\n", netBuf.netName, netBuf.netId);
  1014.     interpret(cfg.pBauds[minimum(netBuf.baudCode, cfg.sysBaud)]);
  1015.     strCpy(call, "ATD");          /* Assume SM compatible        */
  1016.     normId(netBuf.netId, blip1);
  1017.     normId(cfg.codeBuf + cfg.nodeId, blip2);
  1018.     getArea(blip2, ours);
  1019.     getArea(blip1, theirs);
  1020.     strCat(call, cfg.codeBuf + cfg.officeStuff);
  1021.     if (strCmp(ours, theirs) != SAMESTRING) {
  1022.     if (!cfg.longHaul)
  1023.         crashout("Supposed to call long distance when LONG-HAUL is 0?");
  1024.     strCat(call, "1");
  1025.     strCat(call, blip1 + 2);
  1026.     }
  1027.     else {
  1028.     strCat(call, blip1 + 5);
  1029.     }
  1030.     strCat(call, "\r");
  1031.     moPuts(call);
  1032.     for (i = 0; i < 4000; i++) {
  1033.     pause(1);
  1034.     if (gotCarrier()) break;
  1035.     }
  1036.     if (gotCarrier())
  1037.     return modStat = haveCarrier = TRUE;
  1038.     outMod('\r');          /* Take SmartModem out of call mode    */
  1039.     return FALSE;
  1040. }
  1041.  
  1042. /************************************************************************/
  1043. /*    moPuts() Put a string out to modem without carr check        */
  1044. /************************************************************************/
  1045. moPuts(s)
  1046. char *s;
  1047. {
  1048.     while (*s) {
  1049.     pause(5);
  1050.     if (cfg.debug) putchar(*s);
  1051.     outMod(*s++);
  1052.     }
  1053. }
  1054.  
  1055. /************************************************************************/
  1056. /*    getArea() Gets the area code                    */
  1057. /************************************************************************/
  1058. getArea(s1, s2)
  1059. char *s1, *s2;
  1060. {
  1061.     int i = 0;
  1062.  
  1063.     while (i < 3) {
  1064.     if (isdigit(*s1))
  1065.        s2[i++] = *s1;
  1066.     s1++;
  1067.     }
  1068.     s2[i] = 0;
  1069. }
  1070.  
  1071. /************************************************************************/
  1072. /*    netMessage() Send message via net                */
  1073. /************************************************************************/
  1074. netMessage()
  1075. {
  1076.     char  notDone = TRUE;
  1077.     label sys, ourCode, theirCode;
  1078.  
  1079.     if (!cfg.netParticipant) {
  1080.     mPrintf("This Citadel is not participating in the net.\n ");
  1081.     return;
  1082.     }
  1083.     if (thisRoom != MAILROOM) {
  1084.     mPrintf("Only mail is being networked at this node at the current time\n");
  1085.     return;
  1086.     }
  1087.     if (!loggedIn || !logBuf.lbflags.NET_PRIVS) {
  1088.     mPrintf("Sorry, you don't have net privileges.\n ");
  1089.     return;
  1090.     }
  1091.     do {
  1092.     getString("system to send to", sys, 20, TRUE, ECHO);
  1093.     if (strLen(sys) == 0) return;
  1094.     if (sys[0] == '?')
  1095.         writeNet(FALSE);
  1096.     else {
  1097.         if (searchNameNet(sys) == ERROR)
  1098.         mPrintf("No such system currently part of the net\n ");
  1099.         else
  1100.         notDone = FALSE;
  1101.     }
  1102.     } while (notDone);
  1103.     getNet(searchNameNet(sys));
  1104.     getArea(&cfg.codeBuf[cfg.nodeId], ourCode);
  1105.     getArea(netBuf.netId, theirCode);
  1106.     if (!cfg.longHaul && strCmp(ourCode, theirCode) != SAMESTRING) {
  1107.     mPrintf("Sorry, local Citadels only, please.\n ");
  1108.     return;
  1109.     }
  1110.     if (strCmp(ourCode, theirCode) != SAMESTRING && logBuf.credit == 0) {
  1111.     mPrintf("Sorry, you have no credit for long distance net.\n ");
  1112.     return;
  1113.     }
  1114.     strCpy(msgBuf.mbaddr, netBuf.netName);
  1115.     makeMessage(FALSE, NULL, FALSE, TRUE);
  1116. }
  1117.  
  1118. /************************************************************************/
  1119. /*    writeNet() write up nodes on the net.                */
  1120. /************************************************************************/
  1121. writeNet(idsAlso)
  1122. char idsAlso;
  1123. {
  1124.     int  rover;
  1125.     char *SystemBaud;
  1126.  
  1127.     outFlag = OUTOK;
  1128.     mPrintf("Systems on the net:\n ");
  1129.     for (rover = 0; rover < cfg.netSize; rover++) {
  1130.     getNet(rover);
  1131.     if (netBuf.nbflags.in_use) {
  1132.         switch (netBuf.baudCode) {
  1133.         case ONLY_300:        SystemBaud = "300";       break;
  1134.         case BOTH_300_1200: SystemBaud = "300/1200";      break;
  1135.         case TH_3_12_24:    SystemBaud = "300/1200/2400"; break;
  1136.         default:        SystemBaud = "invalid!";      break;
  1137.         }
  1138.         mPrintf("%-22s", netBuf.netName);
  1139.         if (idsAlso) mPrintf("%-22s%-16s%s", netBuf.netId,
  1140.             (needToCall(rover)) ? "<need to call>" : "",
  1141.             SystemBaud);
  1142.         mPrintf("\n ");
  1143.     }
  1144.     }
  1145. }
  1146.  
  1147. /************************************************************************/
  1148. /*    searchNameNet() Search net for given node name            */
  1149. /************************************************************************/
  1150. searchNameNet(name)
  1151. label name;
  1152. {
  1153.     int rover;
  1154.  
  1155.     for (rover = 0; rover < cfg.netSize; rover++) {
  1156.     if (netTab[rover].ntflags.in_use &&
  1157.         hash(name) == netTab[rover].ntnmhash) {
  1158.         getNet(rover);
  1159.         if (strCmpU(netBuf.netName, name) == SAMESTRING)
  1160.         return rover;
  1161.     }
  1162.     }
  1163.     return ERROR;
  1164. }
  1165.  
  1166. /************************************************************************/
  1167. /*    netStuff() Handles networking for the sysop            */
  1168. /************************************************************************/
  1169. netStuff()
  1170. {
  1171.     label         who;
  1172.     struct logBuffer lBuf;
  1173.     int          logNo;
  1174.  
  1175.     do {
  1176.     mPrintf("\n Net function: ");
  1177.     switch (toUpper(iChar())) {
  1178.         case 'R':
  1179.         mPrintf("equest File\n ");
  1180.         fileRequest();
  1181.         break;
  1182.         case 'X':
  1183.         mPrintf("\bExit to main menu");
  1184.         return;
  1185.         case 'C':
  1186.         mPrintf("redit setting\n ");
  1187.         getNormStr("who", who, NAMESIZE, ECHO);
  1188.         logNo    = findPerson(who, &lBuf);
  1189.         if (logNo == ERROR)   {
  1190.             mPrintf("No such person\n ");
  1191.             break;
  1192.         }
  1193.         mPrintf("%s currently has %d credits.", who, lBuf.credit);
  1194.         lBuf.credit = getNumber("How many now", 0, 255);
  1195.         if (loggedIn  &&  strCmpU(logBuf.lbname, who) == SAMESTRING)
  1196.             logBuf.credit = lBuf.credit;
  1197.  
  1198.         putLog(&lBuf, logNo);
  1199.  
  1200.         break;
  1201.         case 'V':
  1202.         mPrintf("iew net list\n ");
  1203.         writeNet(TRUE);
  1204.         break;
  1205.         case 'A':
  1206.         mPrintf("dd node to net\n ");
  1207.         addNetNode();
  1208.         break;
  1209.         case 'E':
  1210.         mPrintf("dit a node\n ");
  1211.         editNode();
  1212.         break;
  1213.         case 'N':
  1214.         mPrintf("et privilege toggle\n ");
  1215.         getNormStr("who", who, NAMESIZE, ECHO);
  1216.         logNo    = findPerson(who, &lBuf);
  1217.         if (logNo == ERROR)   {
  1218.             mPrintf("No such person\n ");
  1219.             break;
  1220.         }
  1221.         mPrintf(
  1222.             "%s has %snet privileges\n ",
  1223.             who,
  1224.             (lBuf.lbflags.NET_PRIVS) ? "no " : ""
  1225.         );
  1226.         if (!getYesNo("Confirm"))   break;
  1227.         lBuf.lbflags.NET_PRIVS = !lBuf.lbflags.NET_PRIVS;
  1228.         if (strCmpU(lBuf.lbname, logBuf.lbname) == SAMESTRING)
  1229.             logBuf.lbflags.NET_PRIVS = lBuf.lbflags.NET_PRIVS;
  1230.  
  1231.         putLog(&lBuf, logNo);
  1232.  
  1233.         break;
  1234.         case '?':
  1235.         tutorial("netopt.mnu");
  1236.         break;
  1237.         default:
  1238.         mPrintf(" ?\n ");
  1239.     }
  1240.     } while (1);
  1241. }
  1242.  
  1243. /************************************************************************/
  1244. /*    addNetNode() Add a node to the net listing            */
  1245. /************************************************************************/
  1246. addNetNode()
  1247. {
  1248.     int searcher;
  1249.     label temp;
  1250.  
  1251.     getNormStr("System name", netBuf.netName, NAMESIZE, ECHO);
  1252.     if (strLen(netBuf.netName) == 0) return;
  1253.     getString("System ID", netBuf.netId, NAMESIZE, FALSE, ECHO);
  1254.     if (strLen(netBuf.netId) == 0) return;
  1255.     netBuf.baudCode =getNumber("Baud code (0=300, 1=300/1200, 2=300/1200/2400)",
  1256.                            0, 2);
  1257.     netBuf.nbflags.in_use      = TRUE;
  1258.     netBuf.nbflags.normal_mail = FALSE;
  1259.     netBuf.nbflags.room_files  = FALSE;
  1260.     for (searcher = 0; searcher < cfg.netSize; searcher++)
  1261.     if (netTab[searcher].ntflags.in_use == FALSE) break;
  1262.     if (searcher != cfg.netSize)
  1263.     putNet(searcher);
  1264.     else {
  1265.     netTab =
  1266.     (struct netTable *) realloc(netTab, sizeof (*netTab) * ++cfg.netSize);
  1267.     searcher = cfg.netSize - 1;
  1268.     putNet(searcher);
  1269.     }
  1270.     normId(netBuf.netId, temp);
  1271.     netTab[searcher].ntnmhash = hash(netBuf.netName);
  1272.     netTab[searcher].ntidhash = hash(temp);
  1273. }
  1274.  
  1275. /************************************************************************/
  1276. /*    editNode() Edit a net node                    */
  1277. /************************************************************************/
  1278. editNode()
  1279. {
  1280.     label sysname, temp;
  1281.     int   place;
  1282.  
  1283.     getNormStr("Name of system to edit", sysname, NAMESIZE, ECHO);
  1284.     if ((place = searchNameNet(sysname)) == ERROR) {
  1285.     mPrintf("%s not listed!\n ", sysname);
  1286.     return;
  1287.     }
  1288.     getNet(place);
  1289.     while (1) {
  1290.     mPrintf("\n (%s) edit fn: ", netBuf.netName);
  1291.     switch (toUpper(iChar())) {
  1292.         case 'X':
  1293.         mPrintf("\bExit to net menu");
  1294.         normId(netBuf.netId, temp);
  1295.         netTab[place].ntnmhash = hash(netBuf.netName);
  1296.         netTab[place].ntidhash = hash(temp);
  1297.         netTab[place].ntflags.in_use = netBuf.nbflags.in_use;
  1298.         putNet(place);
  1299.         return;
  1300.         case 'B':
  1301.         mPrintf("aud code change\n ");
  1302.     netBuf.baudCode =getNumber("Baud code (0=300, 1=300/1200, 2=300/1200/2400)",
  1303.                            0, 2);
  1304.         break;
  1305.         case 'N':
  1306.         mPrintf("ame change\n ");
  1307.         getNormStr("System name", netBuf.netName, NAMESIZE, ECHO);
  1308.         break;
  1309.         case 'I':
  1310.         mPrintf("D change\n ");
  1311.         getString("System ID", netBuf.netId, NAMESIZE, FALSE, ECHO);
  1312.         break;
  1313.         case 'K':
  1314.         mPrintf("ill node from list\n ");
  1315.         if (getYesNo("Confirm")) {
  1316.             netBuf.nbflags.in_use = FALSE;
  1317.             putNet(place);
  1318.             sPrintf(temp, "a:%d.ml", thisNet);
  1319.             temp[0] = cfg.netDisk + 'a';
  1320.             unlink(temp);
  1321.             return;
  1322.         }
  1323.         break;
  1324.         case '?':
  1325.         tutorial("netedit.mnu");
  1326.         break;
  1327.         default:
  1328.         mPrintf("?\n ");
  1329.     }
  1330.     }
  1331. }
  1332.  
  1333. /************************************************************************/
  1334. /*    inNetTime() Time to network?                    */
  1335. /************************************************************************/
  1336. inNetTime(hr, mn)
  1337. int hr, mn;
  1338. {
  1339.     int thisHour, thisMin;
  1340.  
  1341.     thisHour = cfg.netHour + (cfg.netLength / 60);
  1342.     thisMin  = cfg.netLength - ((thisHour - cfg.netHour) * 60);
  1343.     if (hr < cfg.netHour) return FALSE;
  1344.     if (hr > thisHour)      return FALSE;
  1345.     if (mn >= thisMin)      return FALSE;
  1346.     return TRUE;
  1347. }
  1348.  
  1349. /************************************************************************/
  1350. /*    fileRequest() For network requests of files.            */
  1351. /************************************************************************/
  1352. fileRequest()
  1353. {
  1354.     struct fl_req file_data;
  1355.     label system, dr, data;
  1356.     char   loc[100];
  1357.     char  abort, goodname;
  1358.     FILE  *temp, *fopen();
  1359.     char  *cd, *gcdir();
  1360.     int   place;
  1361.  
  1362.     getNormStr("system to request file from", system, NAMESIZE, ECHO);
  1363.     if (strLen(system) == 0) return;
  1364.     if ((place = searchNameNet(system)) == ERROR) {
  1365.     mPrintf("%s not listed!\n ", system);
  1366.     return;
  1367.     }
  1368.     getNet(place);
  1369.     sPrintf(loc, "name of room on %s that has desired file", system);
  1370.     getNormStr(loc, file_data.room, NAMESIZE, ECHO);
  1371.     if (strLen(file_data.room) == 0) return;
  1372.     getNormStr("the file's name", file_data.roomfile, NAMESIZE, ECHO);
  1373.     if (strLen(file_data.roomfile) == 0) return;
  1374.     getString("what drive you want the file put on", dr, 2, FALSE, ECHO);
  1375.     if (strLen(dr) == 0) return;
  1376.     file_data.drive = dr[0];
  1377.     mPrintf("Now we want to specify the exact directory on drive ");
  1378.     mPrintf("%c to place the file in. ", toUpper(dr[0]));
  1379.     mPrintf("Type the exact path, from the root.");
  1380.     mPrintf(" If you want it in the root directory, then just type ");
  1381.     mPrintf("Return. There is some error checking here, but not much.");
  1382.     mPrintf(" '?' will abort.");
  1383.     abort = FALSE;
  1384.     setSpace(toUpper(dr[0]) - 'A', "");
  1385.     cd = gcdir("");
  1386.     good_path(file_data.path, 98);
  1387.     if (file_data.path[1] != '?') {
  1388.     chdir(file_data.path);
  1389.     do {
  1390.         getString("name the file will be stored under on this system",
  1391.                     file_data.filename, NAMESIZE, FALSE, ECHO);
  1392.         if (strLen(file_data.filename) == 0) abort = TRUE;
  1393.         else {
  1394.         temp = fopen(file_data.filename, "r");
  1395.         if (temp != NULL) {
  1396.             fclose(temp);
  1397.             mPrintf("'%s' already exists, and ", file_data.filename);
  1398.             mPrintf("will be overwritten during networking.");
  1399.             goodname = getYesNo("Is this what you want");
  1400.         }
  1401.         else goodname = TRUE;
  1402.         }
  1403.     } while (!abort && !goodname);
  1404.     }
  1405.     else abort = TRUE;
  1406.  
  1407.     chdir(cd);
  1408.     free(cd);
  1409.     setSpace(cfg.homeDisk, "");
  1410.     if (!abort) {
  1411.     sPrintf(data, "a:%d.rfl", place);
  1412.     data[0] = cfg.netDisk + 'a';
  1413.     temp = fopen(data, "ab");
  1414.     if (temp == NULL) {
  1415.         mPrintf("Couldn't append to '%s'????", data);
  1416.     }
  1417.     fwrite(&file_data, sizeof (file_data), 1, temp);
  1418.     fclose(temp);
  1419.     netBuf.nbflags.room_files = TRUE;
  1420.     putNet(place);
  1421.     }
  1422. }
  1423.